package com.byedu.domain.course.vo;

import com.byedu.domain.course.CourseDO;
import com.byedu.domain.course.LibraryDO;
import com.byedu.model.enums.LibraryTypeEnum;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class CourseBuyVO implements Serializable {
	private static final long serialVersionUID = -256152219661444735L;
    /*课程编号*/
    private Integer id;
    /*所属行业*/
    private String industry;
    /*课程名*/
    private String name;

    private String img;
    /*课程简介*/
    private String intro;
    /*售价*/
    private int price;
    /*开放时间*/
    private String openTime;

    public boolean isPay() {
        return pay;
    }

    public void setPay(boolean pay) {
        this.pay = pay;
    }

    private boolean pay;

    private List<PatternVO> patterns;

    public CourseBuyVO() {}

    public List<PatternVO> getPatterns() {
        return patterns;
    }

    public void setPatterns(List<PatternVO> patterns) {
        this.patterns = patterns;
    }

    public CourseBuyVO(CourseDO courseDO, List<LibraryDO> libraryDOs) {
        this.id = courseDO.getId();
        this.industry = courseDO.getIndustry();
        this.name = courseDO.getName();
        this.intro = courseDO.getIntro();
        this.price = courseDO.getPrice();
        this.img = courseDO.getImg();
        this.openTime = courseDO.getOpenTime();
        //分类
        List<PatternVO>  patterns = new ArrayList<>();

        if (libraryDOs != null) {
                for(LibraryTypeEnum libraryType : LibraryTypeEnum.values()){
                    PatternVO pattern = new PatternVO();
//                    pattern.setOpen(false);
//                    pattern.setOpenTrial(false);
                    pattern.setPattern(libraryType.name());
//                    pattern.setPatternName(libraryType.getTitle());
//                    pattern.setClassIcon(libraryType.getClassIcon());

                    List<LibraryVO> libraryVOs = new ArrayList<>();
                    for(LibraryDO libraryDO : libraryDOs){
                        if(libraryType.name().equals(libraryDO.getLibraryType())){
//                            if (libraryDO.getTrialNum() > 0) {
//                                pattern.setOpenTrial(true);
//                            }
//                            pattern.setOpen(true);

                            LibraryVO libraryVO = new LibraryVO(libraryDO);
                            libraryVOs.add(libraryVO);
                        }
                    }
                    pattern.setLibraries(libraryVOs);
                    patterns.add(pattern);
                }
            }

        this.patterns = patterns;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getIndustry() {
        return industry;
    }

    public void setIndustry(String industry) {
        this.industry = industry;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIntro() {
        return intro;
    }

    public void setIntro(String intro) {
        this.intro = intro;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getOpenTime() {
        return openTime;
    }

    public void setOpenTime(String openTime) {
        this.openTime = openTime;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CourseBuyVO courseVO = (CourseBuyVO) o;

        if (id != null ? !id.equals(courseVO.id) : courseVO.id != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "CourseVO{" +
                "id=" + id +
                ", industry='" + industry + '\'' +
                ", name='" + name + '\'' +
                ", intro='" + intro + '\'' +
                ", price=" + price +
                ", openTime='" + openTime + '\'' +
                ", pay=" + pay +
                '}';
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }
}
